#include "meetingpoint.h"

MeetingPoint::MeetingPoint(QWidget *parent)
    : QWidget(parent)
{
    initUI();
    setLineEdit(false);
}

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
void MeetingPoint::initUI()
{
    QHBoxLayout *pHBLayoutPushBtn = new QHBoxLayout();
    for(int index = 1; index < 8; index++)
    {
        QString strValue = QString("连接%1").arg(QString::number(index));
        CustomPushButton *pPushBtn = new CustomPushButton(strValue);
        m_vectPushBtn.push_back(pPushBtn);
        connect(pPushBtn,  SIGNAL(signalClicked(QString)), this, SLOT(onPushBtn(QString)));
        pHBLayoutPushBtn->addWidget(pPushBtn);
        pHBLayoutPushBtn->setSpacing(0);
    }

    QGridLayout *pGridLayout = new QGridLayout();
    QLabel *plabelType = new QLabel("类型:", this);
    m_pLineEdit_Type = new QLineEdit(this);
    pGridLayout->addWidget(plabelType, 0, 0, 1, 2, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_Type, 0, 2, 1, 2);

    QLabel *plabelIncomingRoad = new QLabel("incomingRoad:", this);
    m_pLineEdit_IncomingRoad = new QLineEdit(this);
    pGridLayout->addWidget(plabelIncomingRoad, 1, 0, 1, 2, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_IncomingRoad, 1, 2, 1, 2);

    QLabel *plabelConnectingRoad = new QLabel("connectingRoad:", this);
    m_pLineEdit_ConnectingRoad = new QLineEdit(this);
    pGridLayout->addWidget(plabelConnectingRoad, 2, 0, 1, 2, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_ConnectingRoad, 2, 2, 1, 2);

    QLabel *plabelLaneLink = new QLabel("LaneLink:", this);
    pGridLayout->addWidget(plabelLaneLink, 3, 0);

    QLabel *plabelLaneLinkFrom1 = new QLabel("From", this);
    m_pLineEdit_LaneLinkFrom1 = new QLineEdit(this);
    QLabel *plabelLaneLinkTo1 = new QLabel("To", this);
    m_pLineEdit_LaneLinkTo1 = new QLineEdit(this);
    pGridLayout->addWidget(plabelLaneLinkFrom1, 4, 0, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_LaneLinkFrom1, 4, 1);
    pGridLayout->addWidget(plabelLaneLinkTo1, 4, 2, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_LaneLinkTo1, 4, 3);

    QLabel *plabelLaneLinkFrom2 = new QLabel("From", this);
    m_pLineEdit_LaneLinkFrom2 = new QLineEdit(this);
    QLabel *plabelLaneLinkTo2 = new QLabel("To", this);
    m_pLineEdit_LaneLinkTo2 = new QLineEdit(this);
    pGridLayout->addWidget(plabelLaneLinkFrom2, 5, 0, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_LaneLinkFrom2, 5, 1);
    pGridLayout->addWidget(plabelLaneLinkTo2, 5, 2, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_LaneLinkTo2, 5, 3);

    QLabel *plabelController = new QLabel("controller:", this);
    pGridLayout->addWidget(plabelController, 6, 0);

    QLabel *plabelControllerID = new QLabel("ID:", this);
    m_pLineEdit_ControllerID = new QLineEdit(this);
    QLabel *plabelControllerType = new QLabel("type:", this);
    m_pLineEdit_ControllerType = new QLineEdit(this);
    pGridLayout->addWidget(plabelControllerID, 7, 0, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_ControllerID, 7, 1);
    pGridLayout->addWidget(plabelControllerType, 7, 2, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_ControllerType, 7, 3);

    QVBoxLayout *pVBLayout = new QVBoxLayout();
    pVBLayout->addLayout(pHBLayoutPushBtn);
    pVBLayout->addLayout(pGridLayout);

    setLayout(pVBLayout);
}

void MeetingPoint::setLineEdit(bool bState)
{
    m_pLineEdit_Type->setEnabled(bState);
    m_pLineEdit_IncomingRoad->setEnabled(bState);
    m_pLineEdit_ConnectingRoad->setEnabled(bState);
    m_pLineEdit_LaneLinkFrom1->setEnabled(bState);
    m_pLineEdit_LaneLinkTo1->setEnabled(bState);
    m_pLineEdit_LaneLinkFrom2->setEnabled(bState);
    m_pLineEdit_LaneLinkTo2->setEnabled(bState);
    m_pLineEdit_ControllerID->setEnabled(bState);
    m_pLineEdit_ControllerType->setEnabled(bState);
}

#include <QDebug>
void MeetingPoint::onPushBtn(QString strName)
{
    qDebug() << "MeetingPoint::onPushBtn(QString strName) " << strName;
}
